//axios 封装
//请求拦截器
import Vue from 'vue'
import axios from 'axios';
import VueAxios from 'vue-axios';
import Qs from 'qs';
import storage from "@/utils/storage";

Vue.use(VueAxios, axios);

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    config.headers['Accept'] = 'application/json';
    const token = storage.get('token');
    if(token){
        config.headers['Authorization'] = 'Bearer ' + token;
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
// 定义基础路由
let base = '/api';
// 大驼峰命名请求方法名称
//登录
export const Captcha = params => { return axios.get(`${base}/captcha`, params).then(res => res)};
export const UserLogin = params => { return axios.post(`${base}/login`, Qs.stringify(params)).then(res => res)};
export const UserLogout = params => { return axios.post(`${base}/logout`, Qs.stringify(params)).then(res => res)};
//管理员
export const ManagerList = params => { return axios.get(`${base}/manager`, params).then(res => res)};
export const ManagerUpdate = params => { return axios.post(`${base}/manager/update`, Qs.stringify(params)).then(res => res)};
export const ManagerDestroy = params => { return axios.post(`${base}/manager/destroy`, Qs.stringify(params)).then(res => res)};
export const ManagerLock = params => { return axios.post(`${base}/manager/lock`, Qs.stringify(params)).then(res => res)};
export const ManagerUnlock = params => { return axios.post(`${base}/manager/unlock`, Qs.stringify(params)).then(res => res)};
//配置
export const ConfigInfo = params => { return axios.get(`${base}/config`, params).then(res => res)};
export const ConfigUpdate = params => { return axios.post(`${base}/config/update`, Qs.stringify(params)).then(res => res)};
//标签
export const TagList = params => { return axios.get(`${base}/tag`, params).then(res => res)};
export const TagUpdate = params => { return axios.post(`${base}/tag/update`, Qs.stringify(params)).then(res => res)};
export const TagDestroy = params => { return axios.post(`${base}/tag/destroy`, Qs.stringify(params)).then(res => res)};
//分类
export const CateList = params => { return axios.get(`${base}/cate`, params).then(res => res)};
export const CateAll = params => { return axios.get(`${base}/cate/all`, params).then(res => res)};
export const CateUpdate = params => { return axios.post(`${base}/cate/update`, Qs.stringify(params)).then(res => res)};
export const CateDestroy = params => { return axios.post(`${base}/cate/destroy`, Qs.stringify(params)).then(res => res)};
//新闻
export const NewList = params => { return axios.get(`${base}/new`, params).then(res => res)};
export const NewAll = params => { return axios.get(`${base}/new/all`, params).then(res => res)};
export const NewInfo = params => { return axios.get(`${base}/new/info`, params).then(res => res)};
export const NewUpdate = params => { return axios.post(`${base}/new/update`, Qs.stringify(params)).then(res => res)};
export const NewDestroy = params => { return axios.post(`${base}/new/destroy`, Qs.stringify(params)).then(res => res)};
export const NewAgree = params => { return axios.post(`${base}/new/agree`, Qs.stringify(params)).then(res => res)};
export const NewRefuse = params => { return axios.post(`${base}/new/refuse`, Qs.stringify(params)).then(res => res)};
//seo
export const SeoList = params => { return axios.get(`${base}/seo`, params).then(res => res)};
export const SeoUpdate = params => { return axios.post(`${base}/seo/update`, Qs.stringify(params)).then(res => res)};
export const SeoDestroy = params => { return axios.post(`${base}/seo/destroy`, Qs.stringify(params)).then(res => res)};
//导航
export const ChanelList = params => { return axios.get(`${base}/chanel`, params).then(res => res)};
export const ChanelUpdate = params => { return axios.post(`${base}/chanel/update`, Qs.stringify(params)).then(res => res)};
export const ChanelDestroy = params => { return axios.post(`${base}/chanel/destroy`, Qs.stringify(params)).then(res => res)};
//友情链接
export const FriendList = params => { return axios.get(`${base}/friend`, params).then(res => res)};
export const FriendUpdate = params => { return axios.post(`${base}/friend/update`, Qs.stringify(params)).then(res => res)};
export const FriendDestroy = params => { return axios.post(`${base}/friend/destroy`, Qs.stringify(params)).then(res => res)};
//快讯
export const LiveList = params => { return axios.get(`${base}/live`, params).then(res => res)};
export const LiveUpdate = params => { return axios.post(`${base}/live/update`, Qs.stringify(params)).then(res => res)};
export const LiveDestroy = params => { return axios.post(`${base}/live/destroy`, Qs.stringify(params)).then(res => res)};
//项目
export const ProjectList = params => { return axios.get(`${base}/project`, params).then(res => res)};
export const ProjectAll = params => { return axios.get(`${base}/project/all`, params).then(res => res)};
export const ProjectInfo = params => { return axios.get(`${base}/project/info`, params).then(res => res)};
export const ProjectUpdate = params => { return axios.post(`${base}/project/update`, Qs.stringify(params)).then(res => res)};
export const ProjectDestroy = params => { return axios.post(`${base}/project/destroy`, Qs.stringify(params)).then(res => res)};

//学院
export const CollegeList = params => { return axios.get(`${base}/college`, params).then(res => res)};
export const CollegeInfo = params => { return axios.get(`${base}/college/info`, params).then(res => res)};
export const CollegeUpdate = params => { return axios.post(`${base}/college/update`, Qs.stringify(params)).then(res => res)};
export const CollegeDestroy = params => { return axios.post(`${base}/college/destroy`, Qs.stringify(params)).then(res => res)};

//单页
export const PageList = params => { return axios.get(`${base}/page`, params).then(res => res)};
export const PageInfo = params => { return axios.get(`${base}/page/info`, params).then(res => res)};
export const PageUpdate = params => { return axios.post(`${base}/page/update`, Qs.stringify(params)).then(res => res)};
export const PageDestroy = params => { return axios.post(`${base}/page/destroy`, Qs.stringify(params)).then(res => res)};

//用户
export const UserList = params => { return axios.get(`${base}/user`, params).then(res => res)};
export const UserUpdate = params => { return axios.post(`${base}/user/update`, Qs.stringify(params)).then(res => res)};
export const UserDestroy = params => { return axios.post(`${base}/user/destroy`, Qs.stringify(params)).then(res => res)};
export const UserColumn = params => { return axios.get(`${base}/user/column`, params).then(res => res)};
export const UserVerify = params => { return axios.post(`${base}/user/verify`, Qs.stringify(params)).then(res => res)};
export const UserRefuse = params => { return axios.post(`${base}/user/refuse`, Qs.stringify(params)).then(res => res)};
export const UserColumnAll = params => { return axios.get(`${base}/user/column/all`, params).then(res => res)};











